const path = require('path')

function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  // 基础资源路径 需与 域名的后缀一致
  publicPath: process.env.NODE_ENV === 'production' ? '/pure' : '/',
  // 打包输出的文件路径
  outputDir: `dist/pure-mobile-${process.env.NODE_ENV}`,
  chainWebpack: config => {
    // 路径别名
    config.resolve.alias
      .set('@', resolve('./src'))
      .set('@api', resolve('./src/api'))
      .set('@assets', resolve('./src/assets'))
      .set('@comp', resolve('./src/components'))
  },
  configureWebpack: {
    // 项目名称
    name: process.env.VUE_APP_TITLE
  },
  devServer: {
    // 反向代理
    proxy: {
      [process.env.VUE_APP_BASE_API]: {
        target: `http://localhost`,
        changeOrigin: true,
        pathRewrite: {
          ['^' + process.env.VUE_APP_BASE_API]: ''
        }
      }
    }
  },
  css: {
    loaderOptions: {
      sass: {
        // 全局引入 的 scss
        prependData: `
          @import "~@/scss/global-var.scss";
          @import "~@/scss/mixin.scss";
        `,
        implementation: require('sass')
      }
    }
  }
}
